﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BitPortal.Models;
using BitPortal.Utils;

namespace BitPortal.Business
{
    public static partial class FeedbackBLL
    {
        /// <summary>
        /// Xoa truc tiep
        /// </summary>
        /// <param name="article"></param>
        /// <returns></returns>
        public static int DeletePermanently(long feedID)
        {
            ExtendedBitPortalEntities bitEnt = new ExtendedBitPortalEntities();
            Feedback feed = bitEnt.Feedbacks.SingleOrDefault(a => a.FeedbackID == feedID);
            if (feed != null)
            {
                bitEnt.Feedbacks.DeleteObject(feed);
            }
            return bitEnt.SaveChanges();

        }

        /// <summary>
        /// Xoa tam thoi (dat IsDelete = true)
        /// </summary>
        /// <param name="articleID"></param>
        /// <returns></returns>
        public static int Delete(long feedID)
        {
            ExtendedBitPortalEntities bitEnt = new ExtendedBitPortalEntities();
            Feedback a = bitEnt.Feedbacks.SingleOrDefault(ent => ent.FeedbackID == feedID);
            a.IsDelete = true;
            return bitEnt.SaveChanges();
        }


        public static int Insert(this Models.Feedback feed)
        {
            ExtendedBitPortalEntities bitEnt = new ExtendedBitPortalEntities();
            bitEnt.Feedbacks.AddObject(feed);
            return bitEnt.SaveChanges();
        }

        public static Feedback GetByID(long feedID)
        {
            return (new ExtendedBitPortalEntities()).Feedbacks.SingleOrDefault(ent => ent.FeedbackID == feedID);
        }

        public static IQueryable<Feedback> GetAll()
        {
            ExtendedBitPortalEntities bitEnt = new ExtendedBitPortalEntities();
            var list = from ent in bitEnt.Feedbacks
                       where ent.IsDelete == false
                       select ent;
            return list;
        }

    }
}